package com.wbt.spring.e02.service;

import cn.binarywang.tools.generator.ChineseNameGenerator;
import com.wbt.common.utils.ChineseName;
import com.wbt.spring.e02.dao.UserDao;
import com.wbt.common.beans.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Component
public class UserService {

    private static List<String> workList = new ArrayList<String>();

    static {
        workList.add("Java工程师");workList.add("Python工程师");
        workList.add("C工程师");workList.add("GO工程师");
        workList.add("C++工程师");workList.add("PHP工程师");
        workList.add("C#工程师");workList.add("前端工程师");
        workList.add("测试工程师"); workList.add("运维工程师");
        workList.add("产品经理");workList.add("项目经理");
        workList.add("技术总监");workList.add("CEO");
    }


    @Autowired
    private UserDao userDao;

    public void addUser(User user){
        userDao.addUser(user);
    }

    public void addUsers(int num){
        User user = null;
        for (int i = 0; i < num ; i++ ){
            user = new User();
            user.setUserName(ChineseNameGenerator.getInstance().generate());
            int age = (int)(Math.random() * 70 )+ 18;
            user.setAge(age);
            if(age >  40 && new Random().nextInt(100) >= 98){
                user.setWork(workList.get(new Random().nextInt(14)));
            }else {
                user.setWork(workList.get(new Random().nextInt(12)));
            }

            addUser(user);
        }
    }

    //查询记录数
    public int  selectUserCount() {
        return userDao.selectCount();
    }

    public User findUserInfo(String id) {
        return userDao.findUserInfo(id);
    }

    public List<User> findAllUser(){
        return userDao.findAllUser();
    }
}
